package com.kadron.item;

import java.math.BigDecimal;

import com.kadron.datamodel.KModel;
import com.kadron.entity.Discount;
import com.kadron.entity.Item;
import com.kadron.entity.KItemImage;
import com.kadron.paging.KRow;

public class KItemModel implements KModel,KRow {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6757945160101438919L;
	
	private boolean marked;
	private Item item;
	private KItemImage img;
	private boolean lastOffer;//This property should indicate that in 2-3 days K-SHIRT will be removed from sale.
	
	private Discount discount;// Last discount for this item
	private BigDecimal price; //Price of Item
	private BigDecimal discountPrice; //Price included DISCOUNT
	private BigDecimal yourPrice;// Final price for user, which can be less that discountPrice if silver or gold,.....
	
	public KItemModel(Item item, KItemImage image) {
		super();
		this.item = item;
		this.img = image;
	}

	public boolean isMarked() {
		return marked;
	}

	public void setMarked(boolean marked) {
		this.marked = marked;
	}

	@Override
	public long getId() {
		return item.getId();
	}

	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public KItemImage getImg() {
		return img;
	}

	public void setImg(KItemImage image) {
		this.img = image;
	}

	public boolean isLastOffer() {
		return lastOffer;
	}

	public void setLastOffer(boolean lastOffer) {
		this.lastOffer = lastOffer;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (item.getId() ^ (item.getId() >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		KItemModel other = (KItemModel) obj;
		if (item.getId() != other.item.getId())
			return false;
		return true;
	}

	public Discount getDiscount() {
		return discount;
	}

	public void setDiscount(Discount discount) {
		this.discount = discount;
	}

	public BigDecimal getDiscountPrice() {
		return discountPrice;
	}

	public void setDiscountPrice(BigDecimal discountPrice) {
		this.discountPrice = discountPrice;
	}

	public BigDecimal getYourPrice() {
		return yourPrice;
	}

	public void setYourPrice(BigDecimal yourPrice) {
		this.yourPrice = yourPrice;
	}
	
	public boolean isDiscounted() {
		return discount != null && discount.isActive();
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	
}
